//
//  SuggestionsController.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 16/6/27.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "SuggestionsController.h"
#import "BRPlaceholderTextView.h"

@interface SuggestionsController ()<UITextViewDelegate>

@property (strong, nonatomic)  BRPlaceholderTextView *SuggesTextView;

@property(nonatomic) BOOL judgePost;

@end

@implementation SuggestionsController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(SuggestionsSubmitDidClick)];
    [self.navigationItem.rightBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:15],NSFontAttributeName, nil] forState:UIControlStateNormal];
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor whiteColor]];
    
    
    
    self.title = @"意见反馈";
    _judgePost = false;
    [self setupSuggestionsUI];
}

- (void)setupSuggestionsUI
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    UIImageView *bgImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Suggestions.jpg"]];
    [self.view addSubview:bgImg];
    bgImg.frame = CGRectMake(0,0,WIDTH,HEIGHT - NavBar_StatusHEIGHT);
    
    BRPlaceholderTextView *SuggesTextView=[[BRPlaceholderTextView alloc] initWithFrame:CGRectMake(10,10, WIDTH-10*2,HEIGHT/3)];
    self.SuggesTextView = SuggesTextView;
    SuggesTextView.placeholder=@"请输入内容,最多不超过300字";
    SuggesTextView.font=[UIFont boldSystemFontOfSize:14];
    SuggesTextView.layer.borderColor=[UIColor lightGrayColor].CGColor;
    [self.view addSubview:SuggesTextView];
    
    [SuggesTextView setPlaceholderColor:[UIColor grayColor]];
    [SuggesTextView setPlaceholderOpacity:0.6];
    [SuggesTextView addMaxTextLengthWithMaxLength:300 andEvent:^(BRPlaceholderTextView *text) {
        
        NSLog(@"亲~最多不超过300字");
    }];
    
    [SuggesTextView addTextViewBeginEvent:^(BRPlaceholderTextView *text) {
        NSLog(@"begin");
        NSLog(@"%@",text);
    }];
    
    
    __weak typeof (self)weakself = self;
    [self.SuggesTextView addTextViewEndEvent:^(BRPlaceholderTextView *text) {
        NSLog(@"end%@",text.text);

            NSDictionary *params = @{
                                     @"username":USERNAME,
                                     @"content":text,
                                     @"phone":USERNAME
                                     };
            
            [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"/api/Pub/feedback" completeBlock:^(id object) {
                
                NSLog(@"%@",object);
                
                if (JudgeBackDataCode) {
                
                    MBProgressHUD *hud = [MBProgressHUD showMessage:@"反馈成功" toView:weakself.view dimBackground:NO AndCompleteBlock:^(id object) {
                        
                        [weakself.navigationController popViewControllerAnimated:YES];
                    }];
                    [weakself.view addSubview:hud];
                }
                
            }];

    }];

}



- (void)SuggestionsSubmitDidClick
{
    [self.SuggesTextView endEditing:YES];
  
}


@end
